<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="com.luzhikun.EL_JSTL.Person" %>
<%@ page import="com.luzhikun.EL_JSTL.Student" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 小柒的Java
  Date: 2021/4/28
  Time: 8:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

<%--
    遍历1到10 输出
        begin属性设置 开始的索引
        end属性设置  结束的索引
        var属性表示循环的变量(也是遍历的当前的值)
        for(int i=1 ;i<10;i++){
        }
--%>

</table>
<c:forEach begin="1" end="10" var="i">
    <%--1 2 3 4 5 6 7 8 9 10--%>
    <%--<h1>${i}</h1>--%>
    <%--${i}<br>--%>
    <tr>
        <td>第${i}行</td>
    </tr>
</c:forEach>
</table>
<hr>
<%--
    遍历Object数组
    Object[] o={"1242141","441414","5135451"}
    java中：
    for(Object arr;o){
    }
    items表示遍历的数据源(要遍历的集合)
    item表示当前遍历到数据

--%>
<% request.setAttribute("arr", new Object[]{"1242141", "441414", "5135451"});%>

<table border="1px" cellspacing="0px">
    <c:forEach items="${requestScope.arr}" var="item">
        <%--<h1>${i}</h1>--%>
        <%--${i}<br>--%>
        <tr>
            <td>${item}</td>
        </tr>
    </c:forEach>
</table>
<hr>

<% request.setAttribute("arrays",new Object[]{1,"2","3",4,5});%>
<c:forEach var="a" items="${requestScope.arrays}">
    <tr>
        <td>${a}</td></br>
    </tr>
</c:forEach>
<%--
      遍历Map集合
      Map map=new HashMap();
      原java中
      for(Map.Entry<String,Object> entry:map.entrySet()){
               Object obj= entry.getvalue();
               sout(obj);
      }

--%>

<%
    Map<String, Object> map = new HashMap();
    map.put("1", "value1");
    map.put("2", "value2");
    map.put("3", "value3");

    request.setAttribute("entryMap", map);
%>

<c:forEach items="${requestScope.entryMap}" var="entry">
    ${entry.key}<br>
    ${entry.value}<br>
</c:forEach>
<hr>


<%--
    遍历list集合

    items表示遍历的集合
    var表示当前遍历到的值
    begin表示遍历的开始【索引】值
    end表示遍历结束的【索引】值
    step属性表示遍历的步长值  类似于java中for循环中的i++  默认步长值为1
--%>
<%
    List list = new ArrayList<>();
    for (int i = 1; i < 10; i++) {
        list.add(new Student(i, "name" + i, "111" + i, 18 + i));
    }
    request.setAttribute("thisList", list);
%>


<table border="1px" cellspacing="0px">
    <tr align="center">
        <td>学号</td>
        <td>姓名</td>
        <td>密码</td>
        <td>年龄</td>
        <td>操作</td>

    </tr>
    <c:forEach begin="2" end="6" step="2" varStatus="end" items="${thisList}" var="student">
        <tr>
            <td>${student.id}</td>
            <td> ${student.name}</td>
            <td>${student.password}</td>
            <td>${student.age}</td>
            <td> ${end.step} </td>
        </tr>
    </c:forEach>
</table>


</body>
</html>
